package pe.gob.osinergmin.service.impl;

import android.content.Context;

import java.util.ArrayList;
import java.util.List;

import pe.gob.osinergmin.bean.SupervisionMovilDetalleSCOP;
import pe.gob.osinergmin.dao.SupervisionMovilDetalleScopDAO;
import pe.gob.osinergmin.dao.impl.SupervisionMovilDetalleScopDAOImpl;
import pe.gob.osinergmin.service.SupervisionMovilDetalleScopService;
import pe.gob.osinergmin.utils.PuntoControlUtils;

public class SupervisionMovilDetalleScopServiceImpl implements SupervisionMovilDetalleScopService {

    private static SupervisionMovilDetalleScopDAO supervisionMovilDetalleScopDAO;

    private static SupervisionMovilDetalleScopServiceImpl instance;

    public SupervisionMovilDetalleScopServiceImpl() {
        super();
        supervisionMovilDetalleScopDAO = SupervisionMovilDetalleScopDAOImpl.getInstance();
    }

    @Override
    public List<SupervisionMovilDetalleSCOP> getSupervisionMovilDetalleSCOPList(Context context, SupervisionMovilDetalleSCOP supervisionMovilDetalleSCOP) throws Exception {
        List<SupervisionMovilDetalleSCOP> supervisionMovilDetalleScopList = supervisionMovilDetalleScopDAO.getSupervisionMovilDetalleSCOPList(context);
        List<SupervisionMovilDetalleSCOP> result = null;
        if(supervisionMovilDetalleSCOP != null){
            for(SupervisionMovilDetalleSCOP _supervisionMovilDetalleSCOP : supervisionMovilDetalleScopList){
                if(PuntoControlUtils.compareObjects(_supervisionMovilDetalleSCOP, supervisionMovilDetalleSCOP)){
                    if(result == null) result = new ArrayList<>();
                    result.add(_supervisionMovilDetalleSCOP);
                }
            }
        }else{
            result = supervisionMovilDetalleScopList;
        }
        return result;
    }

    @Override
    public void saveSupervisionMovilDetalleSCOPListToLocal(Context context, List<SupervisionMovilDetalleSCOP> supervisionMovilDetalleSCOPList) throws Exception {
        supervisionMovilDetalleScopDAO.saveSupervisionMovilDetalleSCOPListToLocal(context, supervisionMovilDetalleSCOPList);
    }

    @Override
    public void deleteSupervisionMovilDetalleSCOPListFromLocal(Context context) {
        supervisionMovilDetalleScopDAO.deleteSupervisionMovilDetalleSCOPListFromLocal(context);
    }

    public static SupervisionMovilDetalleScopServiceImpl getInstance(){
        if(instance == null) {
            instance = new SupervisionMovilDetalleScopServiceImpl();
        }
        return instance;
    }
}
